package com.bjpowernode.ba04;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import sun.dc.pr.PRError;

@Component("student4")
public class Student {

    @Value("多尔衮")
    private String name;
    @Value("50")
    private Integer age;


    /*
        使用@Autowired的byName
        1.在属性上面加@Autowired
        2.在属性上面加@Qualifier(value="bean的id"):表示由指定的bean来完成引用类型属性的赋值


        关于@Autowired的属性required
            属性required是一个Boolean类型，默认是true
            required=true表示引用类型赋值失败，程序报错，并且终止执行
            required=false表示引用类型如果赋值失效，程序继续正常执行，引用类型的值为null
    */
    @Autowired()
    @Qualifier(value = "school4")
    private School school;

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", school=" + school +
                '}';
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setAge(Integer age) {
        this.age = age;
    }
}
